package sentryx

import (
	"common/configx"
	"github.com/getsentry/sentry-go"
	"io"
	"time"
)

type SentryXStruct struct {
	io.Writer
}

var SentryX *SentryXStruct

// Init 初始化
func Init() error {
	SentryX = &SentryXStruct{}
	return sentry.Init(
		sentry.ClientOptions{
			Dsn:              configx.C.Sentry.Dns,
			EnableTracing:    configx.C.Sentry.EnableTracing,
			TracesSampleRate: configx.C.Sentry.TracesSampleRate,
		},
	)
}

func (stx *SentryXStruct) Write(p []byte) (n int, err error) {
	sentry.CaptureMessage(string(p))
	defer sentry.Flush(time.Second * 2)
	return 0, nil
}
